/**
 * 
 */
package com.whu.waterworks.service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import com.whu.waterworks.dao.QualityNormolDao;
import com.whu.waterworks.model.QualityNormol;

/**
 * @author： Joymin
 * @date：2016-4-2 下午4:53:17
 * 说明: 
 */
public class QualityNormolService {
	private boolean flag=false;	
	private QualityNormolDao  qualityNormolDao;
	
	public String addQualityNormol(QualityNormol norm,String type){
		//录入限值
		String message="";
		if(type.equals("1")){
			System.out.println("type=1");
			QualityNormol temp=qualityNormolDao.getLimitedQualityNormol();
			if(null!=temp){
				flag=qualityNormolDao.updateQualityNormol(norm);
			}
			else{				
				//norm.setwaterplantId("000000000000");
				norm.setType("1");
				flag=qualityNormolDao.saveQualityNormol(norm);
			}			
		}
		//录入检测数据
		else{
			System.out.println("type=0");
			norm.setType("0");			
			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");//设置日期格式			
			System.out.println(norm.getTime());
			if(null==norm.getId()){
				flag=qualityNormolDao.saveQualityNormol(norm);
			}
			else{
				flag=qualityNormolDao.updateQualityNormol(norm);
			}			
		}
		if(flag){
			message="提交成功！";
		}
		else{
			message="提交失败，请稍后！";
		}
		return message;
	}
	
	public QualityNormol getDataOfLimitNorm(){
		return qualityNormolDao.getLimitedQualityNormol();
	}
	
	public String delQualityNormol(QualityNormol norm){
		String message="";
		flag=qualityNormolDao.delQualityNormol(norm);
		if(flag){
			message="删除成功！";
		}
		else{
			message="删除失败，请稍后！";
		}
		return message;
	}
	
	
	public QualityNormolDao getQualityNormolDao() {
		return qualityNormolDao;
	}
	public void setQualityNormolDao(QualityNormolDao qualityNormolDao) {
		this.qualityNormolDao = qualityNormolDao;
	}
	
//zhoululu
	public List<QualityNormol> getQualityNormols(String code,String startTime,String endTime){
		return qualityNormolDao.getQualityNormols(code, startTime, endTime);	
	}
	
	public QualityNormol getQualityNormolById(String id){
		return qualityNormolDao.getQualityNormolById(id);
	}
	

}
